#include <algorithm>
#include <cstdio>
#include <cstring>

typedef long long ll;
const int N = 20005, M = 15, bit = 62;
int n, q;
int e_cnt, heads[N], f[M][N], dep[N], _log[M];
ll g[N];

struct Edge {
  int v, nxt;
} e[N << 1];

struct Base {
  ll base[bit];
  Base() : base() { memset(base, 0, sizeof(base)); }
  inline void insert(ll x) {
    if (!x) return;
    for (int i = bit - 1; ~i; --i) {
      if ((x >> i) & 1) {
        if (base[i])
          x ^= base[i];
        else {
          base[i] = x;
          return;
        }
      }
    }
  }

  inline ll query() {
    ll res = 0;
    for (int i = bit - 1; ~i; --i) {
      if (!((res >> i) & 1))
        if (base[i]) res ^= base[i];
    }
    return res;
  }

  inline friend Base merge(const Base &lhs, const Base &rhs) {
    Base res;
    for (int i = bit - 1; ~i; --i) {
      res.insert(lhs.base[i]), res.insert(rhs.base[i]);
    }
    return res;
  }
} b[M][N];

inline void add(int u, int v) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt;
}

void dfs(int x) {
  b[0][x].insert(g[x]);
  for (int i = 1; i < M; ++i) {
    f[i][x] = f[i - 1][f[i - 1][x]];
    b[i][x] = merge(b[i - 1][x], b[i - 1][f[i - 1][x]]);
  }
  for (int i = heads[x], v; i; i = e[i].nxt) {
    if ((v = e[i].v) != f[0][x]) {
      f[0][v] = x, dep[v] = dep[x] + 1;
      dfs(v);
    }
  }
}

inline int lca(int x, int y) {
  if (dep[x] < dep[y]) std::swap(x, y);
  for (int i = M - 1; ~i; --i) {
    if (dep[f[i][x]] >= dep[y]) {
      x = f[i][x];
    }
  }
  if (x == y) return x;
  for (int i = M - 1; ~i; --i) {
    if (f[i][x] != f[i][y]) {
      x = f[i][x], y = f[i][y];
    }
  }
  return f[0][x];
}

inline int kth(int x, int k) {
  for (int i = M - 1; ~i; --i)
    if ((k >> i) & 1) x = f[i][x];
  return x;
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("P3292 [SCOI2016]幸运数字.in", "r", stdin);
  freopen("P3292 [SCOI2016]幸运数字.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &g[i]); 
  }
  for (int i = 1, x, y; i < n; ++i) {
    scanf("%d%d", &x, &y);
    add(x, y), add(y, x);
  }
  f[0][1] = 1, dep[1] = 1;
  dfs(1);
  _log[1] = 0;
  for (int i = 2; i <= n; ++i) _log[i] = _log[i >> 1] + 1;
  int u, v, mlca, k;
  while (q--) {
    scanf("%d%d", &u, &v);
    mlca = lca(u, v);
    k = _log[dep[u] - dep[mlca] + 1];
    Base tmp = b[k][u];
    if (dep[u] - dep[mlca] + 1 != (1 << k))
      tmp = merge(tmp, b[k][kth(u, dep[u] - dep[mlca] + 1 - (1 << k))]);
    k = _log[dep[v] - dep[mlca] + 1];
    tmp = merge(tmp, b[k][v]);
    if (dep[v] - dep[mlca] + 1 != (1 << k))
      tmp = merge(tmp, b[k][kth(v, dep[v] - dep[mlca] + 1 - (1 << k))]);
    printf("%lld\n", tmp.query());
  }
  return 0;
}